<template>
  <div class="smrz-form">
    <el-form ref="form" :model="form" label-width="82px" v-loading="ztLoading">
      <div class="sf-top">
        平台认证
      </div>
      <el-form-item style="position: relative" prop="tenantName" :rules="vType('','企业名称',true,'blur')" label="企业名称">
        <el-input placeholder="请输入企业名称" disabled
                  v-model="form.tenantName">
        </el-input>
        <a class="a-icon" @click="refreshPage">
          <i style="font-size: 28px;color: #afaaaa" class="el-icon-refresh"></i>
        </a>
      </el-form-item>
      <el-form-item prop="uscCode" :rules="vType('uscCode','企业税号',true,'blur')"
                    label="企业税号">
        <el-input placeholder="请输入企业税号" disabled
                  v-model="form.uscCode">
        </el-input>
      </el-form-item>
      <el-form-item prop="pin" :rules="vType('','证书口令',true,'blur')"
                    label="证书口令">
        <el-input type="password" placeholder="请输入证书口令"
                  v-model="form.pin">
        </el-input>
      </el-form-item>

<!--      <el-checkbox style="margin-left: 52px; color: #a1aaef;" label="阅读并同意《数据授权协议》" name="type" v-model="xyCheck"></el-checkbox>-->
      <div class="sf-bottom">
        <el-button type="warning" class="kyc-btn sf-btn" @click="submitForm">
          认证
        </el-button>
      </div>
    </el-form>
    <el-dialog class="client-error" width="38%" title="提示" :visible.sync="dialogVisible">
      <div class="eTips">
        <span class="el-icon-warning-outline">中天易税云助手未启动</span>
        <div style="color: rgb(102, 102, 102); font-weight: normal;">
          <p>
            1. 若未安装，请先
            <a href="https://yun.hzztsoft.com/ysyzs/ysyzs.zip">
              下载
            </a>
            后手动安装
          </p>
          <p data-v-2194a942="">
            2. 若已安装，请
            <a href="ztYun:">
            启动
            </a>
            中天易税云助手
          </p>
          <p>
            3. 若已安装并启动，请
            <a @click="refreshPage">刷新</a>
            页面
          </p>
        </div>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {ztyun} from '@/api/tszs/tszs';

export default {
  name: "smrz",
  data() {
    return {
      form: {
        uscCode: '',
        tenantName: '',
        pin:''
      },
      /*xyCheck:false,*/
      url: 'https://127.0.0.1:51888?app=ztyun',
      rzUrl: 'https://127.0.0.1:51888/callshell/?app=ztyun',
      dialogVisible:false,
      ztLoading:false
    }
  },
  mounted() {
    this.initSmPage();
  },
  methods: {
    refreshPage(){
      this.dialogVisible=false;
      this.initSmPage();
    },
    initSmPage() {
      let _ = this;
      this.ztLoading = true;
      let params = {funcNo: '201'};
      this.$refs.form.clearValidate();
      ztyun(this.url,params).then(res => {
        _.form.tenantName = res.nsrmc;
        _.form.uscCode = res.nsrsbh;
        _.ztLoading = false;
        _.dialogVisible = false;
      }).catch(e => {
        _.dialogVisible = e.retCode?false:true;
        _.ztLoading = false;
      })
    },
    submitForm() {
      let _ = this;
      this.$refs.form.validate((valid) => {
        if (valid) {
          let params = {funcNo: '204',nsrsbh:_.form.uscCode,pin:_.form.pin};
          ztyun(_.rzUrl,params).then(res => {
            _.$emit('smrz',_.form);
          })
          /*if(_.xyCheck){

          }else{
            _.$message({
              message: '请阅读并同意《数据授权协议》！',
              type: 'error'
            });
          }*/
        } else {
          return false;
        }
      });
    }
  }
}
</script>

<style lang="scss">
.smrz-form {
  width: 370px;
  margin: 0px auto;
  border-radius: 8px;
  padding: 40px 0;

  .a-icon{
    position: absolute;
    width: 40px;
    right: -8px;
    padding-top: 5px;
  }
  .sf-top{
    width: 100%;
    text-align: center;
    font-weight: bold;
    font-size: 22px;
    margin: 40px 0
  }
  .sf-bottom {
    text-align: center;
    margin-top: 20px;

    .sf-btn {
      width: 100%;
      border-radius: 6px;
    }
  }
  .el-form-item__label{
    font-weight: normal!important;
  }
}
.client-error{

  .eTips{
    font-weight: 700;
    font-size: 14px;
    line-height: 20px;
    color: red;
    text-align: left;
    padding-left: 15px;
    height: 280px;
    a{
      font-weight: bold;
      color: rgb(43, 135, 208);
      text-decoration: underline;
    }
  }
  .eTips>span{
    font-weight: 700
  }
  .eTips>span:before {
    padding-right: 2px
  }
  .eTips p{
    padding-left: 15px
  }
}


</style>
